// pages/hotel/hotel.js
// import http from "../../utils/http"
const app = getApp()
const common = require('../../../public.js')

Page({
    data: {
        height: 70,//初始高
        chushi: 250,
        isShow: true,//控制小笔的显示和隐藏
        value: "",//输入框的value
        shopInfo: {},//所有信息
        defaultHeight: "95rpx",
        contant: "200rpx",
        tag:true

    },
    onLoad: function (options) {
        var that = this
        this.setData({
            storeId: options.id,
            title: options.name,
        },()=>{
            wx.setNavigationBarTitle({
                title: that.data.title, //页面标题为路由参数
              })
            this.shopInfo()
        })
    
     
    },
    onShow: function () {
    },
      // 时间戳
      time(time) {
        return common.dateFormat('yyyy-MM-dd HH:mm', time)
      },
    async shopInfo() {
        var that = this

        var  tempJson ={
            storeId: that.data.storeId,
            // storeId:33,
            xpoint: this.data.lat,
            ypoint: this.data.lon,
            xcFlag: '0' //是否含有携程门票 0不含有
        }
   
        common.get('/store/mainPageInfo', tempJson, res => {
                res.data.store.openTime = res.data.store.openTime.split("-")
            for (let i = 0; i < res.data.couponList.length; i++) {
                const startTimeStr = res.data.couponList[i].beginTime
                const endTimeStr = res.data.couponList[i].finishTime
                res.data.couponList[i].beginTime = that.timestampToTime(startTimeStr)
                res.data.couponList[i].finishTime = that.timestampToTime(endTimeStr)
            }
            if(res.data.commentList){
                for(var i = 0;i < res.data.commentList.length;i++){
                    res.data.commentList[i].addTime=that.time( res.data.commentList[i].addTime)
                }
            }
            this.setData({
                couponList: res.data.couponList,
                shopInfo: res.data,
                defaultItemList: res.data.itemCatList2.defaultItemList.slice(0,3),
            })
        })
    },
    // 点击查看更多
    more() {
        if(this.data.tag == true){  //展开
            let defaultHeight = "auto"
            let contant = defaultHeight + '30rpx'
            let tag = false
            this.setData({
                defaultHeight,
                contant,
                tag
            })
        }else{
            // 收起
          let tag =true
          this.setData({
            defaultHeight:"95rpx",
            contant:"200rpx",
            tag
          })
        }

    },
    // 地图导航
    clickMap() {
        if (!this.data.shopInfo.store.xpoint || !this.data.shopInfo.store.ypoint) {
            common.showToast('商家未设置位置信息')
            return
        }
        let lon = parseFloat(this.data.shopInfo.store.xpoint)
        let lat = parseFloat(this.data.shopInfo.store.ypoint)
        wx.openLocation({
            latitude: lon,
            longitude:lat,
            scale: 18,
            fail: () => {
                wx.showToast({
                    title: '无地址信息',
                    icon: "none"
                })
            }
        })
    },
     // 拨打电话
     call() {
        wx.makePhoneCall({
            phoneNumber: this.data.shopInfo.store.mobile,
            fail: function () { }
        })
    },
    // 触发焦点
    focus() {
        this.setData({
            isShow: false,
            height: 150
        })
    },
    // 失焦
    blur() {
        if (this.value != "") {
            console.log(1);
            this.setData({
                isShow: false,
                chushi: 0,
                height: 70
            })
        } else {
            this.setData({
                isShow: true
            })
        }
    },
    // 评论
    add(e) {
        // console.log(e);

        let value = e.detail.value
        if (value) {
            this.setData({
                value
            })
        }
    },
    send(e) {
        console.log(e);
        wx.showToast({
            title: e.detail.value,
        })
    },

})